package com.example.seckill.utils;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;



/**
 *  @Author: caesar
 *  @Date：2020年12月08日 17:12:58
 *  @Description: 代码自动生成类
 */
public class CodeGenerator {
    public static void main(String[] args) {
        //全局配置
        GlobalConfig globalConfig=new GlobalConfig();
        globalConfig.setAuthor("caesar")//设置作者
                .setActiveRecord(true)//是否支持AR模式
                .setOutputDir("D:\\wsq\\mybatisPlus\\")   //生成文件的路径
                .setFileOverride(true)   //文件覆盖
                .setIdType(IdType.AUTO); //主键策略

        //数据源配置
        DataSourceConfig dataSourceConfig=new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setUrl("jdbc:mysql://192.144.201.111:13306/seckill")
                .setDriverName("com.mysql.cj.jdbc.Driver")
                .setUsername("root")
                .setPassword("cmF0ZWw=");

        //策略配置
        StrategyConfig strategyConfig=new StrategyConfig();
        strategyConfig.setCapitalMode(true)  //全局大写
                .setNaming(NamingStrategy.underline_to_camel)  //数据库表映射到实体的命名策略
                .setInclude("goods","goods_record");//表名,不指定表名生成全部
        // .setTablePrefix("tbl_");//表前缀

        //包名策略
        PackageConfig packageConfig=new PackageConfig();
        packageConfig.setParent("com.example.seckill")
                .setEntity("entity")
                .setMapper("dao")
                .setService("service")
                .setController("controller")
                .setXml("dao");

        AutoGenerator autoGenerator=new AutoGenerator();
        autoGenerator.setDataSource(dataSourceConfig)
                .setPackageInfo(packageConfig)
                .setGlobalConfig(globalConfig)
                .setStrategy(strategyConfig);
        autoGenerator.execute();

    }

}
